package tech.qiantong.qdata.module.da.dal.mapper.assetchild.theme;

import org.apache.ibatis.annotations.Param;
import tech.qiantong.qdata.common.core.page.PageResult;
import tech.qiantong.qdata.module.da.controller.admin.assetchild.theme.vo.DaAssetThemeRelPageReqVO;
import tech.qiantong.qdata.module.da.dal.dataobject.assetchild.theme.DaAssetThemeRelDO;
import tech.qiantong.qdata.mybatis.core.mapper.BaseMapperX;
import tech.qiantong.qdata.mybatis.core.query.LambdaQueryWrapperX;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 数据资产-主题关联关系Mapper接口
 *
 * @author qdata
 * @date 2025-04-14
 */
public interface DaAssetThemeRelMapper extends BaseMapperX<DaAssetThemeRelDO> {

    default PageResult<DaAssetThemeRelDO> selectPage(DaAssetThemeRelPageReqVO reqVO) {
        // 定义排序的字段（防止 SQL 注入，与数据库字段名称一致）
        Set<String> allowedColumns = new HashSet<>(Arrays.asList("id", "create_time", "update_time"));

        // 构造动态查询条件
        return selectPage(reqVO, new LambdaQueryWrapperX<DaAssetThemeRelDO>()
                .eqIfPresent(DaAssetThemeRelDO::getAssetId, reqVO.getAssetId())
                .eqIfPresent(DaAssetThemeRelDO::getThemeId, reqVO.getThemeId())
                .eqIfPresent(DaAssetThemeRelDO::getCreateTime, reqVO.getCreateTime())
                // 如果 reqVO.getName() 不为空，则添加 name 的精确匹配条件（name = '<name>'）
                // .likeIfPresent(DaAssetThemeRelDO::getName, reqVO.getName())
                // 按照 createTime 字段降序排序
                .orderBy(reqVO.getOrderByColumn(), reqVO.getIsAsc(), allowedColumns));
    }


    void deleteDaAssetThemeRelByAssetId(Long id);

    List<Long> getDaAssetIdList(@Param("themeIdList") List<Long> themeIdList);
}
